home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performModifyConstraintAxes. < prev    next >
Encoding:
Text File  |  2003-07-17  |  9.0 KB  |  370 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  August, 2002
  22. //
  23. //  Description:
  24. //        This script provides an option box dialog for
  25. //      restricting the constrained axes.
  26. //
  27. //    Input Arguments:
  28. //        boolean showOptionBox    true - show the option box dialog
  29. //                                false - just execute the command
  30. //
  31. //  Procedure Name:
  32. //      setOptionVars
  33. //
  34. //  Description:
  35. //        Initialize the option values.
  36. //
  37. //  Input Arguments:
  38. //        Whether to set the options to default values.
  39. //
  40. //  Return Value:
  41. //      None.
  42. //
  43. proc setOptionVars(int $forceFactorySettings)
  44. {
  45.     if ($forceFactorySettings || 
  46.         !`optionVar -exists restrictConstraintX`) {
  47.         optionVar -intValue restrictConstraintX 1;
  48.     }
  49.     if ($forceFactorySettings || 
  50.         !`optionVar -exists restrictConstraintY`) {
  51.         optionVar -intValue restrictConstraintY 1;
  52.     }
  53.     if ($forceFactorySettings || 
  54.         !`optionVar -exists restrictConstraintZ`) {
  55.         optionVar -intValue restrictConstraintZ 1;
  56.     }
  57.  
  58.     // maintain existing offset
  59.     //
  60.     if ($forceFactorySettings || 
  61.         !`optionVar -exists restrictAxisMaintainOffset`) {
  62.         optionVar -intValue restrictAxisMaintainOffset 0;
  63.     }
  64. }
  65.  
  66. //
  67. //  Procedure Name:
  68. //      restrictAxesSetup
  69. //
  70. //  Description:
  71. //        Update the state of the option box UI to reflect the option values.
  72. //
  73. //  Input Arguments:
  74. //      parent               - Top level parent layout of the option box UI.
  75. //                             Required so that UI object names can be 
  76. //                             successfully resolved.
  77. //
  78. //        forceFactorySettings - Whether the option values should be set to
  79. //                             default values.
  80. //
  81. //  Return Value:
  82. //      None.
  83. //
  84. global proc restrictAxesSetup(string $parent, int $forceFactorySettings)
  85. {
  86.     //    Retrieve the option settings
  87.     //
  88.     setOptionVars($forceFactorySettings);
  89.  
  90.     setParent $parent;
  91.  
  92.     checkBoxGrp -edit -value1 `optionVar -query restrictConstraintX` restrictXWidget;
  93.     checkBoxGrp -edit -value1 `optionVar -query restrictConstraintY` restrictYWidget;
  94.     checkBoxGrp -edit -value1 `optionVar -query restrictConstraintZ` restrictZWidget;    
  95.         
  96.     checkBoxGrp -edit -value1 `optionVar -query restrictAxisMaintainOffset` restrictAxisMaintainWidget;
  97. }
  98.  
  99. //
  100. //  Procedure Name:
  101. //      restrictAxesCallback
  102. //
  103. //  Description:
  104. //        Update the option values with the current state of the option box UI.
  105. //
  106. //  Input Arguments:
  107. //      parent - Top level parent layout of the option box UI.  Required so
  108. //               that UI object names can be successfully resolved.
  109. //
  110. //        doIt   - Whether the command should execute.
  111. //
  112. //  Return Value:
  113. //      None.
  114. //
  115. global proc restrictAxesCallback(string $parent, int $doIt)
  116. {
  117.     setParent $parent;
  118.  
  119.     //    Set the optionVar's from the control values, and then
  120.     //    perform the command.
  121.  
  122.     optionVar -intValue restrictConstraintX `checkBoxGrp -query -value1 restrictXWidget`;
  123.     optionVar -intValue restrictConstraintY `checkBoxGrp -query -value1 restrictYWidget`;
  124.     optionVar -intValue restrictConstraintZ `checkBoxGrp -query -value1 restrictZWidget`;        
  125.  
  126.     // maintain offset
  127.     //
  128.     optionVar -intValue restrictAxisMaintainOffset `checkBoxGrp -query -value1 restrictAxisMaintainWidget`;
  129.  
  130.     if ($doIt) {
  131.         performModifyConstraintAxes 0;
  132.         addToRecentCommandQueue "performModifyConstraintAxes 0" "ModifyConstraintAxes";
  133.     }
  134. }
  135.  
  136. //
  137. //  Procedure Name:
  138. //      restrictAxesOptions
  139. //
  140. //  Description:
  141. //        Construct the option box UI.  Involves accessing the standard option
  142. //        box and customizing the UI accordingly.
  143. //
  144. //  Input Arguments:
  145. //      None.
  146. //
  147. //  Return Value:
  148. //      None.
  149. //
  150. proc restrictAxesOptions()
  151. {
  152.     //    Name of the command for this option box.
  153.     //
  154.     string $commandName = "restrictAxes";
  155.  
  156.     //    Build the option box actions.
  157.     //
  158.     string $callback = ($commandName + "Callback");
  159.     string $setup = ($commandName + "Setup");
  160.  
  161.     //    Get the option box.
  162.     //
  163.     string $layout = getOptionBox();
  164.     setParent $layout;
  165.     
  166.     //    Pass the command name to the option box.
  167.     //
  168.     setOptionBoxCommandName($commandName);
  169.     
  170.     //    Activate the default UI template.
  171.     //
  172.     setUITemplate -pushTemplate DefaultTemplate;
  173.  
  174.     //    Turn on the wait cursor.
  175.     //
  176.     waitCursor -state 1;
  177.  
  178.     tabLayout -scr true -tv false;
  179.     string $parent = `columnLayout -adjustableColumn 1`;
  180.     
  181.     checkBoxGrp
  182.         -label "Constrain"
  183.         -label1 "X"
  184.         -annotation "Enable to make the constraint act upon the X axis."
  185.         -numberOfCheckBoxes 1
  186.         restrictXWidget;
  187.  
  188.     checkBoxGrp
  189.         -label ""
  190.         -label1 "Y"
  191.         -annotation "Enable to make the constraint act upon the Y axis."
  192.         -numberOfCheckBoxes 1
  193.         restrictYWidget;
  194.  
  195.     checkBoxGrp
  196.         -label1 "Z"
  197.         -annotation "Enable to make the constraint act upon the Z axis."
  198.         -numberOfCheckBoxes 1
  199.         restrictZWidget;
  200.  
  201.     checkBoxGrp
  202.         -label "Maintain Offset"
  203.         -label1 " "
  204.         -annotation "Preserve the current offset of the constrained objects."
  205.         -numberOfCheckBoxes 1
  206.         restrictAxisMaintainWidget;
  207.     
  208.     //    Turn off the wait cursor.
  209.     //
  210.     waitCursor -state 0;
  211.     
  212.     //    Deactivate the default UI template.
  213.     //
  214.     setUITemplate -popTemplate;
  215.  
  216.     //    'Apply' button.
  217.     //
  218.     string $applyBtn = getOptionBoxApplyBtn();
  219.     button -edit
  220.         -label "Modify"
  221.         -command ($callback + " " + $parent + " " + 1)
  222.         $applyBtn;
  223.  
  224.     //    'Save' button.
  225.     //
  226.     string $saveBtn = getOptionBoxSaveBtn();
  227.     button -edit 
  228.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  229.         $saveBtn;
  230.  
  231.     //    'Reset' button.
  232.     //
  233.     string $resetBtn = getOptionBoxResetBtn();
  234.     button -edit 
  235.         -command ($setup + " " + $parent + " " + 1)
  236.         $resetBtn;
  237.  
  238.     //    Set the option box title.
  239.     //
  240.     setOptionBoxTitle("Modify Constrained Axis Options");
  241.  
  242.     //    Customize the 'Help' menu item text.
  243.     //
  244.     setOptionBoxHelpTag( "ModifyConstrainedAxis" );
  245.  
  246.     //    Set the current values of the option box.
  247.     //
  248.     eval (($setup + " " + $parent + " " + 0));    
  249.     
  250.     //    Show the option box.
  251.     //
  252.     showOptionBox();
  253. }
  254.  
  255. //
  256. //  Procedure Name:
  257. //      restrictAxesHelp
  258. //
  259. //  Description:
  260. //        Return a short description about this command.
  261. //
  262. //  Input Arguments:
  263. //      None.
  264. //
  265. //  Return Value:
  266. //      string.
  267. //
  268. proc string restrictAxesHelp()
  269. {
  270.     return 
  271.         ("  Command: Modify Constrained Axes - restrict axes a constraint.\n" + "Selection: <A target to be removed and a constrained object.>");
  272. }
  273.  
  274. //
  275. //  Procedure Name:
  276. //      assembleCmd
  277. //
  278. //  Description:
  279. //        Construct the command that will apply the option box values.
  280. //
  281. //  Input Arguments:
  282. //      None.
  283. //
  284. //  Return Value:
  285. //      None.
  286. //
  287. proc string assembleCmd()
  288. {
  289.     string $cmd = "doModifyConstraintAxes 1 ";
  290.     setOptionVars(false);
  291.  
  292.     int $maintainOffset = `optionVar -q restrictAxisMaintainOffset`;
  293.     int $cx = `optionVar -q restrictConstraintX`;
  294.     int $cy = `optionVar -q restrictConstraintY`;
  295.     int $cz = `optionVar -q restrictConstraintZ`;
  296.     
  297.     $cmd = ($cmd + " { " +
  298.             "\""+ $cx  + "\"" +
  299.             ",\""+ $cy  + "\"" +
  300.             ",\""+ $cz  + "\"" +
  301.             ",\""+ $maintainOffset  + "\"" +                
  302.             "};");
  303.     return $cmd;
  304. }
  305.  
  306. //
  307. //  Procedure Name:
  308. //      performModifyConstraintAxes
  309. //
  310. //  Description:
  311. //        Perform the constraint command using the corresponding 
  312. //        option values related to restricting the constraint axis.
  313. //      This procedure will also show the option box
  314. //        window if necessary as well as construct the command string
  315. //        that will invoke the restrictAxes command with the current
  316. //        option box values.
  317. //
  318. //  Input Arguments:
  319. //      0 - Execute the command.
  320. //      1 - Show the option box dialog.
  321. //      2 - Return the command.
  322. //
  323. //  Return Value:
  324. //      None.
  325. //
  326. global proc string performModifyConstraintAxes(int $action)
  327. {
  328.     string $cmd = "";
  329.  
  330.     switch ($action) {
  331.  
  332.         //    Execute the command.
  333.         //
  334.         case 0:
  335.             //    Retrieve the option settings
  336.             //
  337.             setOptionVars(false);
  338.  
  339.             //    Get the command.
  340.             //
  341.             $cmd = `assembleCmd`;
  342.  
  343.             //    Execute the command with the option settings.
  344.             //
  345.             eval($cmd);
  346.  
  347.             break;
  348.  
  349.         //    Show the option box.
  350.         //
  351.         case 1:
  352.             restrictAxesOptions;
  353.             break;
  354.  
  355.         //    Return the command string.
  356.         //
  357.         case 2:
  358.             //    Retrieve the option settings.
  359.             //
  360.             setOptionVars (false);
  361.  
  362.             //    Get the command.
  363.             //
  364.             $cmd = `assembleCmd`;
  365.             break;
  366.     }
  367.     return $cmd;
  368. }
  369.  
  370.